<?php
/**
 * 权限角色管理
 *
 * @author chenfenghua <843958575@qq.com>
 * version 2.0
 */

namespace app\backend\modules\admin\models;

use Yii;
use app\backend\components\BaseModel;
use app\models\admin\models\AdminGroup;
use app\models\admin\models\AdminRole;

class AppRole extends BaseModel
{
    /**
     * 根据用户Id获取权限
     *
     * @param $user_id
     * @return array
     */
    public function getRoleById($user_id)
    {
        $sql =  'SELECT s.group_name,s.acl FROM '.AdminRole::tableName().
            ' AS t LEFT JOIN '.AdminGroup::tableName().
            ' AS s ON t.role_id = s.role_id '.
            ' WHERE t.user_id = '.$user_id;
        return Yii::$app->db->createCommand($sql)->queryOne();
    }
}